import { Component, OnInit, OnDestroy,ChangeDetectorRef,ChangeDetectionStrategy,ViewChild,ElementRef, Inject, PLATFORM_ID, HostListener } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd/message';
import { FormBuilder, FormGroup, Validators,FormControl } from '@angular/forms';
import { HttpClient } from '@angular/common/http';
import { NzModalRef, NzModalService } from 'ng-zorro-antd/modal';
import { css } from 'jquery';
import * as echarts from 'echarts';
import { NzCarouselModule } from 'ng-zorro-antd/carousel';

@Component({
  selector: 'u14',
  templateUrl: './u14.component.html',
  styleUrls: ['./u14.component.css'],
  changeDetection:ChangeDetectionStrategy.OnPush
})
export class U14Component implements OnInit {
  // @ViewChild('myInput') myInput: ElementRef;
  title = '轴瓦读码识别防错程序';
  timeText = "1";
  NCQty = "0";
  TCQty = "0";
  SVQty = "0";
  ZS550Qty = "0";
  ZS650Qty = "0";
  num="";
  tpType="";
  runningTask="空";
  bufferTask="无";
  carLocation="left"
  private timer:any;
  outPage = false;
  confirm = false;
  cancelConfirm = false;
  pageStyle="background:none";
  array = [1, 2, 3];
  handleCancel(): void {
    this.outPage = false;
    this.confirm = false;
    this.cancelConfirm = false;
    this.closeK();
    this.tpType="";
  }
  constructor(private message: NzMessageService,
    private fb: FormBuilder,
    public http:HttpClient,
    private ref: ElementRef,
    private cd: ChangeDetectorRef,
    private modal: NzModalService,
    private card:NzCarouselModule,
    @Inject(PLATFORM_ID) private platformId: Object
    ) {
    }
  //销毁组件时清除定时器
  ngOnDestroy(){
    
  }
  ngOnInit(): void {
    this.showRealTime();
    this.timer=setInterval(()=>{
      this.showRealTime();
      this.query14();
      this.queryTask();
    },5000)
    this.query14();
    this.queryTask();
  }
  closeK(){
    this.outPage=false;
    this.num = "";
  }
  clearK(){
    this.num = "";
  }
  outBoundPage(tp:any){
    this.outPage = true;
    this.tpType = tp;
  }
  numButton(n:any){
    this.num = n;
  }
  
  showRealTime() {
    let dt = new Date()
    let y = dt.getFullYear()
    let mt = dt.getMonth() + 1
    let day = dt.getDate()
    let h = dt.getHours() //获取时
    let m = dt.getMinutes() //获取分
    let s = dt.getSeconds() //获取秒
    this.timeText =
      y + '年' + mt + '月' + day + '日' + h + '时' + m + '分'
    console.log(this.timeText)

    // let nameDom:any = document.getElementById("cid");
    // nameDom.sheet.insertRule('.card:nth-child(1) svg circle:nth-child(2) { stroke-dashoffset: calc(440 - (440 * 10) / 100);stroke: #00ff43;}', 0);
  }
  //查库存
  query14(){
    console.log("查库存")
    var url="was/services/rest/WasService/Query14";
    this.http.post(url, {"StyleNo": "14"})
      .subscribe((response)=>{
        console.log(response)
        let list:any = response;
        this.NCQty = list[0];
        this.TCQty = list[1];
        this.SVQty = list[2];
        this.ZS550Qty = list[3];
        this.ZS650Qty = list[4];
      })
  }
  //手动创建出库任务
  ConfirmOutBound(){
    var url="was/services/rest/WasService/OutBuffer";
    this.http.post(url, {"StyleNo": this.tpType,"count":this.num})
      .subscribe((response)=>{
        console.log(response)
        let messages:any = response;
        this.message.warning(messages.message);
      })
      this.confirm = false;
      this.cd.markForCheck();
  }
  //显示进行中的任务
  queryTask(){
    var url="was/services/rest/WasService/Query14OutBound";
    this.http.post(url, {"StyleNo": "14"})
      .subscribe((response)=>{
        console.log(response)
        let list:any = response;
        this.runningTask = list[0];
        this.bufferTask = list[1];
      })
  }
  showConfirm(){
    if(this.num!=""){
      this.confirm=true;
    }else{
      this.message.error("请输入出库数量");
    }
  }
  cancelTaskButton(){
    this.cancelConfirm=true;
  }
  //取消任务
  ConfirmCancel(){
    var url="was/services/rest/WasService/Cancel14OutBound";
    this.http.post(url, {"StyleNo": "14"})
      .subscribe((response)=>{
        console.log(response)
        let messages:any = response;
        this.message.warning(messages.message);
      })
      this.cancelConfirm=false;
      this.cd.markForCheck();
  }
}
interface ItemData {
  Time: string;
  Message: string;
}

